package com.example.springbootdemo.utils;

import java.util.Random;

public class RandomStringGenerator {
    private static final String DIGITS = "0123456789";
    private static final Random random = new Random();

    public static String generateRandomString(int length) {
        StringBuilder stringBuilder = new StringBuilder(length);

        for (int i = 0; i < length; i++) {
            int randomIndex = random.nextInt(DIGITS.length());
            char randomDigit = DIGITS.charAt(randomIndex);
            stringBuilder.append(randomDigit);
        }

        return stringBuilder.toString();
    }

    public static void main(String[] args) {
        int desiredLength = 18; // 指定你想要的随机字符串长度
        String randomString = generateRandomString(desiredLength);
        System.out.println(randomString);
    }
}
